<?php
session_start();
if(empty($_SESSION['adminUser']))
{
	echo "<script>window.location.href='../';</script>";exit;
}
require('../lib/functions.php');
require('../lib/mySQL.php');
require('../configs/config.php');
$gWeb = new Web();
$INCOME = $gWeb->parse_incoming();
$DB = new DB;
$DB->info['host'] = $CONF['db_host'];
$DB->info['usr']  = $CONF['db_user'];
$DB->info['pwd']  = $CONF['db_pass'];
$DB->info['db']   = $CONF['db_db'];
$DB->db_connect();
mysql_query("set names utf8");
function calc($size,$digits=2){
  $unit= array('','K','M','G','T','P');
  $base= 1024;
  $i   = floor(log($size,$base));
  $n   = count($unit);
  if($i >= $n){
          $i=$n-1;
        }
        return round($size/pow($base,$i),$digits).' '.$unit[$i] . 'B';
}
?>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>无标题文档</title>
</head>

<body>
<h2>内容厨房 统计</h2>
<?php $days = floor((time()-strtotime("2015-05-01"))/86400);?>
累计存储<?php echo str_replace("../res","",exec("du ../res -sh"));?><br/>
<?php $r = $DB->db_query_first("SELECT count(*) as num FROM jeep_resource.admin_info where roleId=3");?>
其中覆盖经销商<?echo $r['num']?>家<br/>

<?php $DB->db_query("select count(*) as num from log_login group by uid");?>
访问用户:<?php echo $DB->db_fetch_num()?>     访问<? echo round($DB->db_fetch_num()/$days,2)?>人次/日<br/><br/>
<?php $r = $DB->db_query_first("SELECT count(*) as num FROM log_down");
      $r2 = $DB->db_query_first("SELECT count(*) as num FROM res_file");
      $r3 = $DB->db_query_first("select count(*) as num from log_login");
      $num = $r['num']+$r2['num']+$r3['num'];
?>
浏览量:<?php echo number_format($num);?>     浏览量<? echo round($num/$days,2)?>人次/日<br/><br/>

<?php $r = $DB->db_query_first("SELECT sum(size) as num FROM log_down")?>
累计下载内容:<?php echo calc($r['num'],2);?>     下载<? echo calc(round($r['num']/$days,2),2)?>人次/日<br/><br/>

<?php $r = $DB->db_query_first("SELECT count(*) as num FROM admin_info")?>
总计开通账户:<?php echo $r['num']?> <br/><br/>
<?php $r = $DB->db_query_first("SELECT count(*) as num FROM admin_info where roleId=2")?>
服务商账号:<?php echo $r['num']?> <br/><br/>
<?php $r = $DB->db_query_first("SELECT count(*) as num FROM admin_info where roleId in(1,4)")?>
克莱斯勒用户:<?php echo $r['num']?> <br/><br/>
<?php $r = $DB->db_query_first("SELECT count(*) as num FROM admin_info where roleId=3")?>
经销商用户:<?php echo $r['num']?> <br/><br/>
<?php $r2 = $DB->db_query_first("select count(*) as num from log_login");?>
<?php $DB->db_query("select count(*) as num from log_login  group by uid");
 
?>
每个用户平均<?php echo round($r2['num']/$DB->db_fetch_num(),2)?>次登陆系统，浏览页面<?php echo round($num/$DB->db_fetch_num(),2)?>页<br/><br/>
--------------------------------------------------------------------------------------------<br/>
<?php  $r2 = $DB->db_query_first("SELECT count(*) as num FROM res_file_subject");?>
<?php  $r3 = $DB->db_query_first("SELECT count(*) as num FROM res_file_subject where isPost=1");?>
素材包<?php echo $r3['num']."/".$r2['num'];?><br/><br/>
<?php  $r2 = $DB->db_query_first("SELECT count(*) as num FROM res_file");?>
<?php  $r3 = $DB->db_query_first("SELECT count(*) as num FROM res_file where isPost=1");?>
文件合计<?php echo $r3['num']."/".$r2['num'];?><br/><br/>
<?php  $r2 = $DB->db_query_first("SELECT sum(size) as num FROM res_file");?>
<?php  $r3 = $DB->db_query_first("SELECT sum(size) as num FROM res_file where isPost=1");?>
文件大小<?php echo calc($r3['num'],2)."/".calc($r2['num'],2);?><br/><br/>
--------------------------------------------------------------------------------------------<br/>
<table>
<?php 
$type[] = "广告投放";
$type[] = "展厅物料";
$type[] = "行摄生活";
$type[] = "产品知识";
$type[] = "媒体素材";
$type[] = "活动视频/图片";
$type[] = "其他";
$type[] = "北美素材";
$type[] = "Logo";
$newType = array();
$total = 0;
foreach($type as $v)
{
	$s = $DB->db_query_first("SELECT count(*) as num FROM `res_file_subject` WHERE typeNames like '%".$v."%' and isDel=0");
	$f = $DB->db_query_first("SELECT count(*) as num FROM `res_file` WHERE typeNames like '%".$v."%' and isDel=0");
	$newType[] = array("n"=>$v,"s"=>$s['num'],"f"=>$f['num']);
	$total = $total+$f['num'];
}
foreach($newType as $v)
{
?>
<tr>
<td><?php echo $v['n']?><td><td width="100px"><?php echo $v['s']?></td><td width="100px"><?php echo $v['f']?></td><td><?php echo round((($v['f']/$total)*100),2)."%"?></td>
</tr>
<?php
}
?>
</table>
--------------------------------------------------------------------------------------------<br/>
<?php $r = $DB->db_query("SELECT * FROM admin_info where roleId!=3")?>
<?php 
while($r=$DB->db_fetch_row())
{
	if($r['email'])
	{
		echo $r['name']."=".$r['email']."<br/>";
	}
}
?>
</body>
</html>
